/**
 * www.jbarreto.com all rights reserved 2011
 */
package com.jbarreto.vc.hibernate;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.Action;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.jbarreto.vc.plugin.HibernatePlugIn;

/**
 * @author JBarreto
 *
 * jj_b_f@yahoo.com.mx
 *
 * 14/01/2011 18:05:31
 */
public abstract class HibernateAction extends Action {

	public Session getSession(HttpServletRequest request){

		System.out.println("Getting session factory");
		/* Get the servlet context */
		ServletContext context = request.getSession().getServletContext();
		/* Retrieve Session Factory */
		SessionFactory sessionFactory = (SessionFactory) context
				.getAttribute(HibernatePlugIn.SESSION_FACTORY_KEY);
		/* Open Hibernate Session */
		Session session = sessionFactory.openSession();

		return session;
	}
}
